<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增游戏管理')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-recreation-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">游戏名：</label>
            <div class="col-sm-8">
                <input name="gameName" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">游戏图标：</label>
            <div class="col-sm-8">
                <input id="img" type="hidden" name="img">
                <div class="file-loading">
                    <input class="form-control file-upload" id="file" name="file" type="file" accept=".jpg, .png, .jpeg">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "dl/recreation"
    $("#form-recreation-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-recreation-add').serialize());
        }
    }

    $("#file").fileinput({
        uploadUrl: prefix + "/upload", //上传的地址
        showPreview: true, //是否显示预览
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        maxFileSize: 0,
        allowedPreviewTypes: ['image'],
        allowedFileTypes: ['image'],
        allowedFileExtensions : ['jpg', 'png', 'jpeg'],
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
    }).on('fileuploaded', function (event, data, previewId, index) {
        //同步上传成功回调，如果是异步上传成功会回调fileuploaded，用错的话，回调是不会执行的
        //通过 data.response.Json对象属性 获得返回数据
        if (data.response.code == 0) {
            $("#img").val(data.response.data)
        } else {
            $.modal.alertWarning(data.response.msg);
        }
    });

</script>
</body>
</html>
